<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
<!--    <el-form-item label="会员编号" prop="memberId">-->
<!--      <el-input v-model="dataForm.memberId" placeholder="会员编号"></el-input>-->
<!--    </el-form-item>-->
      <el-form-item label="会员编号" prop="memberId">
        <el-select v-model="dataForm.memberId" placeholder="请选择">
          <el-option v-for="(item,i) in memberModel" :label="item.memberNameConcatId" :value="item.memberId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="菜品名称" prop="orderdishId">
        <el-select v-model="dataForm.orderdishId" placeholder="请选择">
          <el-option v-for="(item,i) in orderDishModel" :label="item.orderdishName" :value="item.orderdishId"></el-option>
        </el-select>
      </el-form-item>
<!--    <el-form-item label="送餐人员编号" prop="orderdishEmployeeid">-->
<!--      <el-input v-model="dataForm.orderdishEmployeeid" placeholder="送餐人员编号"></el-input>-->
<!--    </el-form-item>-->
      <el-form-item label="送餐人员编号" prop="orderdishEmployeeid">
        <el-select v-model="dataForm.orderdishEmployeeid" placeholder="请选择">
          <el-option v-for="(item,i) in employeeModel" :label="item.employeeNameConcatId" :value="item.employeeId"></el-option>
        </el-select>
      </el-form-item>
    <el-form-item label="菜品数量" prop="orderdishNum">
      <el-input v-model="dataForm.orderdishNum" placeholder="菜品数量"></el-input>
    </el-form-item>
      <el-form-item label="就餐方式" prop="orderdishType">
        <el-select v-model="dataForm.orderdishType" placeholder="请选择">
          <el-option label="堂食" value="堂食"></el-option>
          <el-option label="送餐" value="送餐"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订餐日期" prop="orderdishDate">
        <el-date-picker
          v-model="dataForm.orderdishDate"
          type="date"
          placeholder="选择日期"
          format="yyyy 年 MM 月 dd 日"
          value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="餐别" prop="orderdishTime">
        <el-select v-model="dataForm.orderdishTime" placeholder="请选择">
          <el-option label="早" value="早"></el-option>
          <el-option label="中" value="中"></el-option>
          <el-option label="晚" value="晚"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否晚点" prop="orderdishResult">
        <el-select v-model="dataForm.orderdishResult" placeholder="请选择">
          <el-option label="晚点" value="晚点"></el-option>
          <el-option label="未晚点" value="未晚点"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单是否完成" prop="orderdishFinsh">
        <el-select v-model="dataForm.orderdishFinsh" placeholder="请选择">
          <el-option label="已完成" value="已完成"></el-option>
          <el-option label="未完成" value="未完成"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    created () {
      this.getDish()
      this.getEmployeeInfo()
      this.getMemberInfo()
    },
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          memberId: '',
          orderdishId: '',
          orderdishEmployeeid: '',
          orderdishNum: '',
          orderdishType: '',
          orderdishDate: '',
          orderdishTime: '',
          orderdishResult: '',
          orderdishFinsh: '',
          createTime: '',
          updateTime: ''
        },
        dataRule: {
          memberId: [
            { required: true, message: '会员编号不能为空', trigger: 'blur' }
          ],
          orderdishId: [
            { required: true, message: '菜品编号不能为空', trigger: 'blur' }
          ],
          orderdishEmployeeid: [
          ],
          orderdishNum: [
            { required: true, message: '菜品数量不能为空', trigger: 'blur' }
          ],
          orderdishType: [
            { required: true, message: '就餐方式不能为空', trigger: 'blur' }
          ],
          orderdishDate: [
            { required: true, message: '送餐日期不能为空', trigger: 'blur' }
          ],
          orderdishTime: [
            { required: true, message: '餐别不能为空', trigger: 'blur' }
          ],
          orderdishResult: [
            { required: true, message: '是否晚点不能为空', trigger: 'blur' }
          ],
          orderdishFinsh: [
            { required: true, message: '订单是否完成不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ]
        },
        orderDishModel: {
          orderdishId: '',
          orderdishName: ''
        },
        employeeModel: {
          employeeId: '',
          employeeNameConcatId: ''
        },
        memberModel: {
          memberId: '',
          memberNameConcatId: ''
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/tb_bs_orderdish/bsorderdish/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.memberId = data.bsOrderdish.memberId
                this.dataForm.orderdishId = data.bsOrderdish.orderdishId
                this.dataForm.orderdishEmployeeid = data.bsOrderdish.orderdishEmployeeid
                this.dataForm.orderdishNum = data.bsOrderdish.orderdishNum
                this.dataForm.orderdishType = data.bsOrderdish.orderdishType
                this.dataForm.orderdishDate = data.bsOrderdish.orderdishDate
                this.dataForm.orderdishTime = data.bsOrderdish.orderdishTime
                this.dataForm.orderdishResult = data.bsOrderdish.orderdishResult
                this.dataForm.orderdishFinsh = data.bsOrderdish.orderdishFinsh
                this.dataForm.createTime = data.bsOrderdish.createTime
                this.dataForm.updateTime = data.bsOrderdish.updateTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/tb_bs_orderdish/bsorderdish/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'memberId': this.dataForm.memberId,
                'orderdishId': this.dataForm.orderdishId,
                'orderdishEmployeeid': this.dataForm.orderdishEmployeeid,
                'orderdishNum': this.dataForm.orderdishNum,
                'orderdishType': this.dataForm.orderdishType,
                'orderdishDate': this.dataForm.orderdishDate,
                'orderdishTime': this.dataForm.orderdishTime,
                'orderdishResult': this.dataForm.orderdishResult,
                'orderdishFinsh': this.dataForm.orderdishFinsh,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      },
      getDish () {
        this.$http({
          url: this.$http.adornUrl(`/tb_bs_orderdish/bsorderdish/getDish`),
          method: 'get'
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.orderDishModel = data.date
          }
        })
      },
      //获取员工信息下拉
      getEmployeeInfo () {
        this.$http({
          url: this.$http.adornUrl(`/tb_bs_protocol/bsprotocol/queryAllEmployee`),
          method: 'get'
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.employeeModel = data.date
          }
        })
      },
      //获取会员信息下拉
      getMemberInfo () {
        this.$http({
          url: this.$http.adornUrl(`/tb_bs_protocol/bsprotocol/queryAllMember`),
          method: 'get'
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.memberModel = data.date
          }
        })
      }
    }
  }
</script>
